package cn.dai.test.da.linkedlist;

import cn.dai.test.da.linkedlist.singleLL.HeroNode;
import cn.dai.test.da.linkedlist.singleLL.SingleLinkedList;
import org.junit.Test;

/**
 * @author ArkD42
 * @file Jdbc01
 * @create 2020 - 06 - 07 - 17:39
 */
public class LinkedListDemoTest {

    @Test
    public void singleLinkedListDemo(){

        HeroNode h1 = new HeroNode(1, "德玛西亚之力", "盖伦");
        HeroNode h2 = new HeroNode(2, "德玛西亚四世", "嘉文");
        HeroNode h3 = new HeroNode(3, "德邦总管", "赵信");
        HeroNode h4 = new HeroNode(4, "圣锤之毅", "波比");

        SingleLinkedList singleLinkedList = new SingleLinkedList();

        /*
        // 普通插入节点
        singleLinkedList.add(garen);
        singleLinkedList.add(gaven);
        singleLinkedList.add(xinZhao);
        singleLinkedList.add(bobi);

        singleLinkedList.show();
        */

        /*
        HeroNode{no=0, name=' ', alias=' ', the_next is HeroNode{no=1, name='德玛西亚之力', alias='盖伦', the_next is HeroNode{no=2, name='德玛西亚四世', alias='嘉文', the_next is HeroNode{no=3, name='德邦总管', alias='赵信', the_next is HeroNode{no=4, name='圣锤之毅', alias='波比', the_next is null}}}}}
        HeroNode{no=1, name='德玛西亚之力', alias='盖伦', the_next is HeroNode{no=2, name='德玛西亚四世', alias='嘉文', the_next is HeroNode{no=3, name='德邦总管', alias='赵信', the_next is HeroNode{no=4, name='圣锤之毅', alias='波比', the_next is null}}}}
        HeroNode{no=2, name='德玛西亚四世', alias='嘉文', the_next is HeroNode{no=3, name='德邦总管', alias='赵信', the_next is HeroNode{no=4, name='圣锤之毅', alias='波比', the_next is null}}}
        HeroNode{no=3, name='德邦总管', alias='赵信', the_next is HeroNode{no=4, name='圣锤之毅', alias='波比', the_next is null}}
        HeroNode{no=4, name='圣锤之毅', alias='波比', the_next is null}
        */

        /*
        // 排序插入节点
        singleLinkedList.addByOrder(bobi);
        singleLinkedList.addByOrder(garen);
        singleLinkedList.addByOrder(gaven);
        singleLinkedList.addByOrder(xinZhao);

        singleLinkedList.show();
        */

        /*
        // 修改节点
        singleLinkedList.add(h4);

        singleLinkedList.show();
        singleLinkedList.update(new HeroNode(4,"哈哈","呵呵"));
        singleLinkedList.show();
        */

        /*
        // 删除此节点
        singleLinkedList.add(h1);
        singleLinkedList.add(h2);
        singleLinkedList.add(h3);
        singleLinkedList.add(h4);

        singleLinkedList.show();
        singleLinkedList.delete(2);
        System.out.println(" - - - - ");
        singleLinkedList.show();
        */

        /*
        // 求节点个数
        singleLinkedList.add(h1);
        singleLinkedList.add(h2);
        singleLinkedList.add(h3);
        singleLinkedList.add(h4);

        int nodes = singleLinkedList.countNode(singleLinkedList.getThe_head());
        System.out.println("节点个数 " + nodes);
         */

        /*
        //查找倒数第k元素
        singleLinkedList.add(h1);
        singleLinkedList.add(h2);
        singleLinkedList.add(h3);
        singleLinkedList.add(h4);

        HeroNode heroNode = singleLinkedList.theLastNodeIn(singleLinkedList.getThe_head(), 3);
        System.out.println(heroNode);
         */

        /*
        singleLinkedList.add(h1);
        singleLinkedList.add(h2);
        singleLinkedList.add(h3);
        singleLinkedList.add(h4);
        singleLinkedList.show();

        singleLinkedList.reverse(singleLinkedList.getThe_head());
        System.out.println(" - - - - ");
        singleLinkedList.show();
        */

        singleLinkedList.add(h1);
        singleLinkedList.add(h2);
        singleLinkedList.add(h3);
        singleLinkedList.add(h4);
        singleLinkedList.show();


        System.out.println(" - - - - ");
        singleLinkedList.reversePrint(singleLinkedList.getThe_head());
    }




}
